(function () {
    "use strict";

    var $stateProviderRef = null;

    angular.module('core').config(config);
    config.$inject = ['$stateProvider', '$urlRouterProvider', '$locationProvider'];

    function config($stateProvider, $urlRouterProvider, $locationProvider) {

        $urlRouterProvider.deferIntercept();
        $urlRouterProvider.otherwise('/home');
        $locationProvider.html5Mode({ enabled: false });

        $stateProviderRef = $stateProvider;
    }

    /* Run específico para carregar as demais rotas dinamicamente usando stateProviderRef */
    angular.module('core').run(run);
    run.$inject = ['$urlRouter', '$http'];

    function run($urlRouter, $http) {
        $http
            .get('/config/getAllRota')
            .success(function (response) {
                angular.forEach(response.Data, function (value, key) {
                    $stateProviderRef.state(value.Codigo, { url: value.Url, views: { 'body': { templateUrl: value.UrlTemplate, controller: value.Controlador } } });
                });
                $urlRouter.sync();
                $urlRouter.listen();
            });
    }

})();


